package com.qiwenshare.file.util;

public class CommUtil {
    //数字
    public static final String REG_NUMBER = ".*\\d+.*";
    //小写字母
    public static final String REG_UPPERCASE = ".*[A-Z]+.*";
    //大写字母
    public static final String REG_LOWERCASE = ".*[a-z]+.*";
    //特殊符号
    public static final String REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*";

    /**
     * 长度至少minLength位,且最大长度不超过maxlength,须包含大小写字母,数字,特殊字符matchCount种以上组合
     * @param password 输入的密码
     * @param minLength 最小长度
     * @param maxLength 最大长度
     * @param matchCount 次数
     * @return 是否通过验证
     */
    public static boolean checkPwd(String password,int minLength,int maxLength,int matchCount){
        //密码为空或者长度小于8位则返回false
        if (password == null || password.length() <minLength || password.length()>maxLength ) return false;

        int i = 0;
        if (password.matches(REG_NUMBER)) i++;
        if (password.matches(REG_LOWERCASE))i++;
        if (password.matches(REG_UPPERCASE)) i++;
        if (password.matches(REG_SYMBOL)) i++;
        return i >= matchCount;
    }
}
